package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessActivity;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.widget.EditTextWithClear;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2018/7/23 19:32
 * 修改备注：
 * ================================================
 */
public class SingUpActivity extends BaseActivity {

    @Bind(R.id.et_name)
    EditTextWithClear etName;
    @Bind(R.id.et_tel)
    EditTextWithClear etTel;


    private String activityId = "";

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_sing_up);
        setTitle("活动报名");
    }

    @Override
    public void initMember() {
        activityId = (String) getIntent().getSerializableExtra("activityId");
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {

        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);

                switch (msg.what) {
                    case MSG.MSG_SIGN_ACTIVITY_SUCCESS:
                        showToast("报名成功");
                        finish();
                        break;
                    case MSG.MSG_SIGN_ACTIVITY_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };

    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_sign})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_sign:
                signUp();
                break;
        }
    }

    private void signUp() {
        String name = etName.getText().toString();
        String tel = etTel.getText().toString();

        if (StringUtil.isStrEmpty(name)) {
            showToast("请填写报名人");
            return;
        }
        if (StringUtil.isStrEmpty(tel)) {
            showToast("请填写联系电话");
            return;
        }

        //报名
        BusinessActivity.signActivity(this, activityId, name, tel, mHandler);
    }
}
